package com.gyg.service.impl;

import com.gyg.constant.CloudConstant;
import com.gyg.domain.*;
import com.gyg.dao.CloudVideoMapper;
import com.gyg.returns.RespCode;
import com.gyg.returns.RespEntity;
import com.gyg.returns.RespTable;
import com.gyg.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyg.vo.PageVO;
import com.gyg.vo.param.*;
import com.gyg.vo.result.VideoResult;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 视频信息表 服务实现类
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@Service
public class CloudVideoServiceImpl extends ServiceImpl<CloudVideoMapper, CloudVideo> implements CloudVideoService {

    @Override
    public RespTable<List<VideoResult>> videoList(FileParam fileParam) {
        Integer count = baseMapper.videoCount(fileParam);

        if (Objects.isNull(count) || 0 == count) {
            return new RespTable<>(RespCode.OK, new ArrayList<>(), 0);
        }

        PageVO pageVO = new PageVO(fileParam.getPage(), fileParam.getLimit(), count);
        fileParam.setPage(pageVO.getBegin() - 1);
        List<VideoResult> videoResultList = baseMapper.videoList(fileParam);

        return new RespTable<>(RespCode.OK, videoResultList, count);
    }

    @Override
    public RespEntity banVideo(BanParam banParam) {
        CloudVideo cloudVideo = CloudVideo.builder()
                .id(banParam.getFileId())
                .videoBan(1)
                .videoImg(CloudConstant.SYSTEM_BAN)
                .build();
        baseMapper.updateById(cloudVideo);

        return new RespEntity(RespCode.SUCCESS);
    }

    @Override
    public RespEntity unsealVideo(BanParam banParam) {
        CloudVideo cloudVideo = CloudVideo.builder()
                .id(banParam.getFileId())
                .videoBan(0)
                .videoImg(CloudConstant.SYSTEM_VIDEO)
                .build();
        baseMapper.updateById(cloudVideo);

        return new RespEntity(RespCode.SUCCESS);
    }


}
